<template>
  <el-menu
    @select="menuClick"
    unique-opened
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
    style="border-right-width: 0;"
    class="el-menu-vertical-demo"
    :default-active = "defaultActive"
  >
    <el-menu-item index="/home">
        <i class="el-icon-s-home"></i>
        <span slot="title">首页</span>
      </el-menu-item>
    <el-submenu
      :key="index"
      :index="index+''"
      v-for="(item, index) in routes"
      v-if="!item.hidden"
    >
      <template slot="title">
        <i :class="item.iconCls"></i>
        <span>{{ item.name }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item
          :index="child.path"
          :key="indexj"
          v-for="(child, indexj) in item.children"
          >{{ child.name }}</el-menu-item
        >
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  components: {},
  data() {
    return {
    };
  },
  methods: {
    menuClick(index) {
      // console.log(index);
      this.$router.push(index);
      let tab = {path: index,name: '首页'};
      if(index != "/home") {
         this.routes.forEach(item => {
          if(item.children) {
            item.children.forEach(chi => {
              if(index == chi.path) {
                tab.name = chi.name;
              }
            })
          }
        })
      }
      this.$store.commit("selectMemu", tab);
    }
  },
  computed: {
    routes() {
      return this.$store.state.menu.routes;
    },
    defaultActive() {
      let a = this.$route.path;
      return a;
    }
  },
};
</script>
<style scoped>
.el-menu {
  height: 100%;
  border: none;
}
.el-scrollbar .el-scrollbar__wrap {
   overflow-x: hidden;
}
</style>